/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cpu.z80.register;

/**
 *
 * @author kennux
 */
public class FlagRegister extends Double8Bit {
    private static int offset = 0;
    public void setCarry() {
        this.setBit(offset + 0);
    }
    public void setAddSubtract() {
        this.setBit(offset + 1);
    }
    public void setOverflow() {
        this.setBit(offset + 2);
    }
    public void setHalfCarry() {
        this.setBit(offset + 4);
    }
    public void setZero() {
        this.setBit(offset + 6);
    }
    public void setSign() {
        this.setBit(offset + 7);
    }

    public boolean getCarry() {
        return this.testBit(offset + 0);
    }
    public boolean getAddSubtract() {
        return this.testBit(offset + 1);
    }
    public boolean getOverflow() {
        return this.testBit(offset + 2);
    }
    public boolean getHalfCarry() {
        return this.testBit(offset + 4);
    }
    public boolean getZero() {
        return this.testBit(offset + 6);
    }
    public boolean getSign() {
        return this.testBit(offset + 7);
    }

    public void clearCarry() {
        this.clearBit(offset + 0);
    }
    public void clearAddSubtract() {
        this.clearBit(offset + 1);
    }
    public void clearOverflow() {
        this.clearBit(offset + 2);
    }
    public void clearHalfCarry() {
        this.clearBit(offset + 4);
    }
    public void clearZero() {
        this.clearBit(offset + 6);
    }
    public void clearSign() {
        this.clearBit(offset + 7);
    }
    public void calcZero(int value) {
        if(value == 0) {
            setZero();
        } else {
            clearZero();
        }
    }
    public void calcSign(int value) {
        if(value < 0) {
            setSign();
        } else {
            clearSign();
        }
    }
    public void calcHalfCarry8(byte value) {
        if (value >= 64 || value <= -64) {
            setHalfCarry();
        } else {
            clearHalfCarry();
        }
    }
}
